package com.haixiaoke.saas.repository.service.impl;

import com.haixiaoke.saas.repository.electronicVisa.service.IContractRecordService;
import com.haixiaoke.saas.repository.mapper.OrgElectronicVisaMapper;
import com.haixiaoke.saas.repository.pojo.OrgElectronicVisa;
import com.haixiaoke.saas.repository.service.IOrgElectronicVisaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 企业电子签信息Service业务层处理
 *
 * @author qixi
 * @date 2023-12-23
 */
@Service
public class OrgElectronicVisaServiceImpl implements IOrgElectronicVisaService {

    @Autowired
    private OrgElectronicVisaMapper orgElectronicVisaMapper;

    @Autowired
    private IContractRecordService contractRecordService;

    /**
     * 查询企业电子签信息
     *
     * @param visaId 企业电子签信息主键
     * @return 企业电子签信息
     */
    @Override
    public OrgElectronicVisa selectOrgElectronicVisaByVisaId(Long visaId) {
        return orgElectronicVisaMapper.selectOrgElectronicVisaByVisaId(visaId);
    }

    /**
     * 查询企业电子签信息列表
     *
     * @param orgElectronicVisa 企业电子签信息
     * @return 企业电子签信息
     */
    @Override
    public List<OrgElectronicVisa> selectOrgElectronicVisaList(OrgElectronicVisa orgElectronicVisa) {
        List<OrgElectronicVisa> orgElectronicVisas = orgElectronicVisaMapper.selectOrgElectronicVisaList(orgElectronicVisa);
        orgElectronicVisas.forEach(e -> e.setContractLeftNumber(e.getContractTotalNumber() - e.getContractUsedNumber()));
        return orgElectronicVisas;
    }

    /**
     * 新增企业电子签信息
     *
     * @param orgElectronicVisa 企业电子签信息
     * @return 结果
     */
    @Override
    public int insertOrgElectronicVisa(OrgElectronicVisa orgElectronicVisa) {
        orgElectronicVisa.setCreateTime(new Date());
        return orgElectronicVisaMapper.insertOrgElectronicVisa(orgElectronicVisa);
    }

    /**
     * 修改企业电子签信息
     *
     * @param orgElectronicVisa 企业电子签信息
     * @return 结果
     */
    @Override
    public int updateOrgElectronicVisa(OrgElectronicVisa orgElectronicVisa) {
        orgElectronicVisa.setUpdateTime(new Date());
        return orgElectronicVisaMapper.updateOrgElectronicVisa(orgElectronicVisa);
    }

    /**
     * 批量删除企业电子签信息
     *
     * @param visaIds 需要删除的企业电子签信息主键
     * @return 结果
     */
    @Override
    public int deleteOrgElectronicVisaByVisaIds(Long[] visaIds) {
        return orgElectronicVisaMapper.deleteOrgElectronicVisaByVisaIds(visaIds);
    }

    /**
     * 删除企业电子签信息信息
     *
     * @param visaId 企业电子签信息主键
     * @return 结果
     */
    @Override
    public int deleteOrgElectronicVisaByVisaId(Long visaId) {
        return orgElectronicVisaMapper.deleteOrgElectronicVisaByVisaId(visaId);
    }

    @Override
    public OrgElectronicVisa selectOrgElectronicVisaByOrgId(Long orgId) {
        return orgElectronicVisaMapper.selectOrgElectronicVisaByOrgId(orgId);
    }

    // @Override
    // public OrgElectronicVisa selectOrgElectronicVisaInfoByOrgId(Long orgId) {
    //     OrgElectronicVisa orgElectronicVisa = orgElectronicVisaMapper.selectOrgElectronicVisaByOrgId(orgId);
    //     if (ObjectUtil.isNull(orgElectronicVisa)) {
    //         throw new BizException("企业电子签信息不存在");
    //     }
    //
    //     Long visaId = orgElectronicVisa.getVisaId();
    //     contractRecordService.selectContractRecordByVisaId(visaId);
    //     return
    //
    // }
}
